﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Coolite.Ext;
using Coolite.Ext.Web;
using SubSonic;
using CXDB; 
 

public partial class main : System.Web.UI.Page
{
    public  int count1 = 0;
    public int count2 = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!Cookies.ChkCook(Cookies.getCookies("cUsername") + "$" + Cookies.getCookies("cSecurityNum"), Cookies.getCookies("cMD5")))
        {
            Response.Redirect("~/Default.aspx");
        }
        TopPanel.Title = Cookies.getCookies("cUsername") + " @ 诚信档案信息管理系统 上次成功登录时间："+ Cookies.getCookies("cintime") +" [<a href='logout.aspx'>退出</a>]";
        if (Cookies.getCookies("clevelid") != "2")
        {
            MenuPanel1.Hidden = true;
        }
        else
        {
            MenuPanel2.Hidden = true;
        }
        if (Cookies.getCookies("clevelid") != "1")
        {
            MenuItem10.Hidden = true;
            mysearch.Hidden = true;
        }
        if (Cookies.getCookies("clevelid") == "1" && Cookies.getCookies("cdeptid") != "1")
        {
            mysearch.Hidden = true;
        } 
        int deptid = int.Parse(Cookies.getCookies("cdeptid"));
        if ((deptid != 12) && (deptid != 7) && (deptid != 10) && (deptid != 15) && (deptid != 16) && (deptid != 17) && (deptid  != 18) && (deptid != 19) && (deptid != 20))
        {
             
            MenuItem24.Hidden = true;
            MenuItem23.Hidden = true;
            MenuItem13.Hidden = true;
            MenuItem32.Hidden = true;
            MenuItem34.Hidden = true;
            MenuItem31.Hidden = true;
            
        }
        if (deptid == 1)
        {
            MenuItem34.Hidden = false;
            MenuItem33.Hidden = true;
            Provider_shenhe_mine.Hidden = true;
            MenuItem7.Hidden = true;
            MenuItem26.Hidden = true;
        }
         
        if (deptid != 3)
        {
            HR_Staff_ReportAdd.Hidden = true;
            MenuItem28.Hidden = true;
        }
        if ((deptid != 6))
        {
            Safty_Staff_ReportAdd.Hidden = true;            
            MenuItem29.Hidden = true;
        }
        if ((deptid != 3) && (deptid != 6))
        {
            MenuItem8.Hidden = true;
            MenuItem27.Hidden = true;
        }
        if (deptid != 5)
        {
            MenuItem2.Hidden = true;
        }
        if (deptid != 2)
        {
            MenuItem3.Hidden = true;
        }
        if (deptid != 1)
        {
            MenuItem5.Hidden = true;
            MenuItem34.Hidden = true;
            MenuItem23.Hidden = true;
        }
        //if ((deptid != 3) && (deptid != 6))
        //{
        //    MenuItem8.Hidden = true;
        //    MenuItem27.Hidden = true;
        //}
        //if ((deptid == 5) && (levelid == 1))
        //{
        //    Provider_shenhe_mine.Visible = true;
        //    MenuItem2.Visible = true;
        //}
        //if ((deptid == 1) && (levelid == 1))
        //{
        //    MenuItem5.Visible = true;
        //}
        //if ((deptid == 2) && (levelid == 1))
        //{
        //    MenuItem3.Visible = true;
        //    Provider_shenhe_mine.Visible = true;
        //}
        int hrCountAll = Sum("cx_staff_hr");
        int hrCount = Sum("cx_staff_hr","dept_master_status","adept_master_status","boss_status");
        int saftyCountAll = Sum("cx_staff_safty");
        int saftyCount = Sum("cx_staff_safty","dept_master_status","safty_master_status","boss_status");
        int companyCount = Sum("cx_company_pingjia","dept_master_status","manager_status");
        int companyCountAll = Sum("cx_company_pingjia");
        int providerCount = Sum("cx_provider","dept_master_status","tech_master_status","office_master_status","boss_status");
        int providerCountAll=Sum("cx_provider");
        Label1.Text ="员工诚信档案（人事）："+ hrCount + "/" + hrCountAll;
        Label2.Text = "员工诚信档案（安监）："+saftyCount + "/" + saftyCountAll;
        Label3.Text = "供应商诚信档案："+companyCount + "/" + companyCountAll;
        Label4.Text = "用电客户诚信档案："+providerCount + "/" + providerCountAll;
        Label5.Text = "总计：" + (hrCount + saftyCount + companyCount + providerCount) + "/" + (hrCountAll + saftyCountAll + companyCountAll + providerCountAll);
        
        
        HrCount();
        SaftyCount();
        ProviderCount();
        CompanyCount();
        PingfenCount();

        backHrCount();
        backSaftyCount();
        backProviderCount();
        backCompanyCount();
        MenuItem10.Text = "数据审核(" + count1 + ")";
        MenuItem26.Text = "退回的数据("+ count2 +")";

        myseach1.Text = "人事员工诚信档案查询(" + ApplyCount("cx_staff_hr") + ")";
        MenuItem20.Text = "安监员工诚信档案查询(" + ApplyCount("cx_staff_safty")+")";
        MenuItem21.Text = "用电客户诚信档案(" + ApplyCount("cx_company_pingjia")+")";
        MenuItem22.Text = "供应商诚信档案(" + ApplyCount("cx_provider")+")";
        MenuItem40.Text = "用电客户评分细节(" + ApplyCount("cx_chengxin")+")";
    }
    
   
    protected int Sum(string tb, params string[] str)
    {
        int count = 0;
        Query q = new Query(tb); 
        for (int i = 0; i <  str.Length; i++)
        {
            q.AddWhere(str[i], 1);
        }
        count = q.GetRecordCount();
        return count;
    }
     
    //人事方面审核计数
    protected void HrCount()
    {
        string deptid=Cookies.getCookies("cdeptid");
        string uid=Cookies.getCookies("cuid");
        Query q = new Query(CxStaffHr.Schema);
        switch (deptid)
        {
            case "3":
                q.AddWhere("adept_masterid", uid);
                q.AddWhere("adept_master_status", 0);
                break;
            case "1":
                q.AddWhere("boss_userid", uid);
                q.AddWhere("adept_master_status", 1);
                q.AddWhere("dept_master_status", 1);
                q.AddWhere("boss_status", 0);
                break;
            default:
                q.AddWhere("dept_master_id", uid);
                q.AddWhere("dept_master_status", 0);
                break;
        }
        HR_Staff_ShenHe.Text = "人事部操作(" + q.GetRecordCount().ToString() + ")";
        count1 += q.GetRecordCount();
    }
    //安监方面审核计数
    protected void SaftyCount()
    {
        string deptid = Cookies.getCookies("cdeptid");
        string uid = Cookies.getCookies("cuid");
        Query q = new Query(CxStaffSafty.Schema);
        switch (deptid)
        { 
            case "6":
                q.AddWhere("safty_masterid", uid);
                q.AddWhere("safty_master_status", 0);
                break;
            case "1":
                q.AddWhere("boss_userid", uid);
                q.AddWhere("safty_master_status", 1);
                q.AddWhere("boss_status", 0);
                q.AddWhere("dept_master_status", 1);
                break;
            default:
                q.AddWhere("dept_master_id", uid);
                q.AddWhere("dept_master_status", 0);
                break;
        }
        Safty_Staff_ShenHe.Text = "安监部操作(" + q.GetRecordCount() + ")";
        count1 += q.GetRecordCount();
    }
    //供应商方面审核计数
    protected void ProviderCount()
    {
        string deptid = Cookies.getCookies("cdeptid");
        string uid = Cookies.getCookies("cuid");
        
        Query q = new Query(CxProvider.Schema);
        q.AddWhere("dept_master_id", uid);
        q.AddWhere("dept_master_status", 0);
        Provider_shenhe_mine.Text = "部门审核("+ q.GetRecordCount() +")";
        count1 += q.GetRecordCount();

        Query q2 = new Query(CxProvider.Schema);
        q2.AddWhere("tech_master_id", uid);
        q2.AddWhere("tech_master_status", 0);
        q2.AddWhere("dept_master_status", 1);
        MenuItem2.Text = "生产技术部审核(" + q2.GetRecordCount() + ")";
        count1 += q2.GetRecordCount();

        Query q3 = new Query(CxProvider.Schema);
        q3.AddWhere("office_master_id", uid);
        q3.AddWhere("office_master_status", 0);
        q3.AddWhere("dept_master_status", 1);
        MenuItem3.Text = "办公室审核(" + q3.GetRecordCount() + ")";
        count1 += q3.GetRecordCount();

        Query q4 = new Query(CxProvider.Schema);
        q4.AddWhere("boss_id", uid);
        q4.AddWhere("dept_master_status", 1);
        q4.AddWhere("office_master_status", 1);
        q4.AddWhere("tech_master_status", 1);
        q4.AddWhere("boss_status", 0);
        MenuItem5.Text = "公司领导审核(" + q4.GetRecordCount() + ")";
        count1 += q4.GetRecordCount();
    }
    //用电客户诚信档案审核计数
    protected void CompanyCount()
    {
        string deptid=Cookies.getCookies("cdeptid");
        string uid=Cookies.getCookies("cuid");

        Query q = new Query(CxCompanyPingJium.Schema);
        q.AddWhere("dept_master_id", uid);
        q.AddWhere("dept_master_status", 0);
        MenuItem32.Text = "部门审核("+ q.GetRecordCount().ToString() +")";
        count1 += q.GetRecordCount();

        Query q2 = new Query(CxCompanyPingJium.Schema);
        q2.AddWhere("other_master_id", uid);
        q2.AddWhere("other_master_status", 0);
        MenuItem33.Text = "相关部门审核(" + q2.GetRecordCount().ToString() + ")";
        count1 += q2.GetRecordCount();

        Query q3 = new Query(CxCompanyPingJium.Schema);
        q3.AddWhere("manager_id", uid);
        q3.AddWhere("dept_master_status", 1);
        q3.AddWhere("other_master_id", SubSonic.Comparison.Is, null).OR("other_master_id", SubSonic.Comparison.GreaterThan, 0).AND("other_master_status", 1);
        q3.AddWhere("manager_status", 0);
        MenuItem34.Text = "公司领导审核(" + q3.GetRecordCount().ToString() + ")";
        count1 += q3.GetRecordCount();

    }
    //用电客户评分审核
    protected void PingfenCount()
    {
        string deptid = Cookies.getCookies("cdeptid");
        if (deptid == "7")
        {
            SqlQuery q = new Select(new Aggregate("guid", AggregateFunction.GroupBy)).From(VwChengxindetail.Schema).Where("status").IsEqualTo(0).And("depid").IsEqualTo(12);
            MenuItem24.Text = "客户评分（审核）(" + q.GetRecordCount() + ")";
            count1 += q.GetRecordCount();
        }
        if(deptid=="10")
        {
            SqlQuery q = new Select(new Aggregate("guid", AggregateFunction.GroupBy)).From(VwChengxindetail.Schema).Where("status").IsEqualTo(0).And("depid").In(15,16,17,18,19,20);
            MenuItem24.Text = "客户评分（审核）(" + q.GetRecordCount() + ")";
            count1 += q.GetRecordCount();
        }

    }

    //人事待办事项
    protected void backHrCount()
    {
        string deptid=Cookies.getCookies("cdeptid");
        string uid=Cookies.getCookies("cuid");
        Query q = new Query(CxStaffHr.Schema);
        q.AddWhere("enteringuserid", uid);
        q.AddWhere("adept_master_status", 2);
        MenuItem28.Text = "人事部(" + q.GetRecordCount().ToString() + ")";
        count2 += q.GetRecordCount();
    }
    //安监部待办事项
    protected void backSaftyCount()
    {
        string uid = Cookies.getCookies("cuid");
        Query q = new Query(CxStaffSafty.Schema);
        q.AddWhere("enteringuserid",uid);
        q.AddWhere("safty_master_status",2);
        MenuItem29.Text = "安监部("+ q.GetRecordCount().ToString() +")";
        count2 += q.GetRecordCount();
    }
    //供应商待办事项
    protected void backProviderCount()
    {
        string uid = Cookies.getCookies("cuid");
        Query q = new Query(CxProvider.Schema);
        q.AddWhere("entering_userid", uid);
        q.AddWhere("dept_master_status", 2);
        MenuItem30.Text = "供应商诚信档案(" + q.GetRecordCount().ToString() + ")";
        count2 += q.GetRecordCount();
    }
    //用电客户诚信档案待办事项
    protected void backCompanyCount()
    {
        string uid = Cookies.getCookies("cuid");
        Query q = new Query(CxCompanyPingJium.Schema);
        q.AddWhere("enter_user_id", uid);
        q.AddWhere("dept_master_status", 2);
        MenuItem31.Text = "用电客户诚信档案("+ q.GetRecordCount().ToString() +")";
        count2 += q.GetRecordCount();
    }

    //查询审核申请统计
    protected string ApplyCount(string tbname)
    {
        Query q = new Query(CxApply.Schema);
        q.AddWhere("bossnod", 0);
        q.AddWhere("tbname", tbname);
        return q.GetRecordCount().ToString();
    }
}
